// export default () => <div>Welcome to next.js!</div>
import React, { useState } from 'react';
import {Form, Icon, Input, Button, Checkbox} from 'antd'
import {textApi,postTest} from '../../api'
import CryptoJS from 'crypto-js'
//import bcrypt from 'crypto-js/tripledes'
// import {hashSync} from 'bcryptjs'
const bcrypt = require('bcryptjs')
import {passWordKey} from '../util'

function hasErrors(fieldsError) {
    return Object.keys(fieldsError).some(field => fieldsError[field]);
  }
  
const Login = (props) =>{
    
    const [userName, setUserName] = useState(null);
    const [passWord, setPassWord] = useState(null);
    const InputChange = (e) =>{
        const target = e.target;
        const value = target.type === 'checkbox' ? target.checked : target.value;
        const name = target.name;
        // if(name == )
         name == "UserName" ? setUserName(value) : setPassWord(value)
       
    }
    const userLogin = () =>{
        //console.log(pwd);
        controlPwd('dasdsadaddasd')
        let _obj = {
            userName,passWord
        }
        postTest('/loginInfor',_obj).then((res) =>{
            
          })
    }
    const controlPwd = (pwd) =>{
        //text
        let ciphertext  = bcrypt.hashSync(pwd, 10);
        //let plaintext  = tripledes.decrypt(ciphertext, _text).toString(CryptoJS.enc.Utf8);
        console.log(ciphertext);
        let oks = bcrypt.compareSync('dasdsadaddasd', '$2a$10$daXzk5oATLVLbL7ILdZlse9JohKRGGOSsCCQdZvVXT.zx8isSaL2m');
        console.log(oks);


        // let _text = 'CONTROL'
        // let ciphertext  = tripledes.encrypt(pwd,_text).toString();
        // let plaintext  = tripledes.decrypt(ciphertext, _text).toString(CryptoJS.enc.Utf8);
    }
    const closedPop = () => {
        props.ishow()       
    }
    return(
        <div className="fixBg">
            <div className="popContent">
                <div className="infors">
                    <Icon onClick={closedPop} className="closed" type="close" />
                    <h3> <span className="iconfont icon-yuncloud259 logos"></span> 登录</h3>
                    <Input name="UserName" className="firstInput" onChange={InputChange} type="text" value={userName} placeholder="请输入账户" />
                    <Input name="PassWord" type="password" onChange={InputChange} value={passWord} placeholder="请输入密码" />
                    <Button onClick={userLogin} type="primary">登 录</Button>
                </div>
            </div>
        </div>
    ) 

}
// const DoLogin = Form.create({ name: 'horizontal_login' })(Login);


  
export default Login
